import { Meta, Story, Props, Canvas } from '@storybook/addon-docs/blocks'
import { config, withDesign } from 'storybook-addon-designs'
import { action } from '@storybook/addon-actions'
import { useArgs } from '@storybook/client-api'

import RadioButton from '@baserow/modules/core/components/RadioButton'

<Meta
    title="Baserow/Form Elements/Radio/RadioButton"
    component={RadioButton}
    parameters={{
        backgrounds: {
            default: 'white',
            values: [
                { name: 'white', value: '#ffffff' },
                { name: 'light', value: '#eeeeee' },
                { name: 'dark', value: '#222222' },
            ],
        },
    }}
    decorators={[
        withDesign,
        (story, context) => {
            const [_, updateArgs] = useArgs()
            return story({ ...context, updateArgs })
        },
    ]}
    argTypes={{
        default: {
            control: 'text',
            description: 'Slot content',
            defaultValue: 'Label',
        },
        modelValue: {
            control: {
                type: 'text',
            },
            defaultValue: '',
        },
        value: {
            control: {
                type: 'text',
            },
            defaultValue: 'option1',
        },
        icon: {
            control: {
                type: 'text',
            },
            defaultValue: 'iconoir-db',
        },
        title: {
            control: {
                type: 'text',
            },
            defaultValue: 'Some content',
        },
        disabled: {
            control: {
                type: 'boolean',
                options: [true, false],
            },
            defaultValue: false,
        },
        loading: {
            control: {
                type: 'boolean',
                options: [true, false],
            },
            defaultValue: false,
        },
    }}
/>

# RadioButton

The RadioButton component behaves like the Radio component but instead of the native circle button, it uses a custom button design.

export const Template = (args, { argTypes, updateArgs }) => ({
    methods: {
        action,
        handleInput(value) {
            const modelValue = value
            updateArgs({ ...args, modelValue })
            action('handleInput')(modelValue)
        },
    },
    components: { RadioButton },
    props: Object.keys(argTypes),
    template: `<RadioButton v-bind="$props" @input="handleInput">${args.default}</RadioButton>`,
})

export const designConfig = {
    type: 'figma',
    url: 'https://www.figma.com/file/W7R2rQW7ohsZMeHRfEcPFW/Design-Library?node-id=53%3A1852&mode=dev',
}

<Canvas>
    <Story
        name="RadioButton"
        parameters={{
            design: config(designConfig),
        }}
    >
        {Template.bind({})}
    </Story>
</Canvas>

## Example

```javascript
<RadioButton></RadioButton>
```

## Props

<Props of={RadioButton} />
